<?php
$microtime = microtime(TRUE);
$curr_time = date("Y-m-d H:i:s");
$vk_dir = "/home/fox/dev/www/vk/reg/";
$temp_dir = "temp-www/ya/";
$is_finished = 0;

$filename = "need_logins.txt";
$fd = fopen($filename, 'r');
$logins = fread($fd, filesize($filename));
fclose($fd);
$logins = split("\n", $logins);

include_once("../class_main_curl.php");
include_once("../functions.php");
$obj_curl  = new main_curl();
$obj_curl->proxy = FALSE;

if(isset($_GET['code']) && isset($_GET['idkey']) && isset($_GET['login'])) {
	$code                = $_GET['code'];
	$idkey               = $_GET['idkey'];
	$login               = $_GET['login'];
	$obj_curl->cookie    = $temp_dir."cookie-".$login.".txt";
	$obj_curl->filename  = $temp_dir."ya2-".$login.".html";
	$obj_curl->url       = "http://passport.yandex.ru/passport?mode=register";
	$obj_curl->post      = "idkey=".$idkey."&step=two&filled=yes&login=";
	$obj_curl->post     .= $logins[$login]."&fname=Mulder&iname=Fox&passwd=blablabla";
	$obj_curl->post     .= "&passwd2=blablabla&hintq=2&udhintq=&hinta=bludo&hintasave=&questnum=";
	$obj_curl->post     .= "&hintqsave=&email=&phonenumber=&code=".$code."&agreed=yes";
	while(($obj_curl->method_main_curl()) === FALSE ) { echo "RESEND\n"; }
	list($is_good_reg) = search_infile($obj_curl->cookie, "yandex_mail", "yandex_mail");
	$is_good_reg = substr($is_good_reg, 1);
	if($is_good_reg == $logins[$login]) { echo $is_good_reg."<BR>\n"; } else { echo "bad registration<BR>\n"; }
	if($login < (count($logins)-1)) {
		$login++;
	} else {
		$is_finished = 1;
		echo "FINISHED\n";
	}
} else {
	$login = 0;
	system("rm ".$temp_dir."*.txt"); system("rm ".$temp_dir."*.html");
	echo "1st time<BR>\n";
}

if($is_finished == 0) {
	$obj_curl->cookie    = $temp_dir."cookie-".$login.".txt";
	$obj_curl->filename  = $temp_dir."ya1-".$login.".html";
	$obj_curl->url       = "http://passport.yandex.ru/passport?mode=register&msg=mail";
	$obj_curl->post      = "step=one&filled=yes&iname=Fox&fname=Mulder&login=".$logins[$login];
	$obj_curl->post     .= "&done=%C4%E0%EB%FC%F8%E5%A0%26%238594%3B";
	while(($obj_curl->method_main_curl()) === FALSE ) { echo "RESEND\n"; }
	list($captcha) = search_infile($obj_curl->filename, "passport.yandex.ru/digits", "idkey=", "\" name=\"captcha\"");
	echo "<IMG SRC=\"http://passport.yandex.ru/digits?idkey=".$captcha."\"><br>\n";
	echo "<FORM action=\"http://vk/reg/reg_ya.php\" method=\"get\">\n";
	echo "<INPUT type=\"hidden\" name=\"idkey\" value=\"".$captcha."\"><BR>\n";
	echo "<INPUT type=\"hidden\" name=\"login\" value=\"".$login."\">[".$login."] ".$logins[$login]."<BR>\n";
	echo "<INPUT type=\"text\" name=\"code\"><BR>\n";
	echo "<INPUT type=\"submit\" value=\"Send\">\n";
	echo "</FORM>\n";
?>  <script type="text/javascript">document.forms[0].code.focus();</script><?php	
}
?>